{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ab1f4129",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python3_Jupyter_Nb_Pd&Docx_讯捷集团DOCX政策内容提取.ipynb\n",
    "# Create By GF 2023-12-26 16:28"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "af909f20",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import re\n",
    "import docx\n",
    "import pandas\n",
    "import pandas as pd\n",
    "import warnings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7e647f09",
   "metadata": {},
   "outputs": [],
   "source": [
    "# FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\n",
    "warnings.filterwarnings(\n",
    "    \"ignore\",\n",
    "    message=\\\n",
    "        \"The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c475704e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# String Function GF Two String Similarity.\n",
    "def StrFunc_Two_String_Similarity(String_A:str, String_B:str) -> float:\n",
    "\n",
    "    Word_Of_Chinese:list = [# 省份(Province)\n",
    "                            \"贵州\", \"陕西\", \"四川\", \"云南\",\n",
    "\n",
    "                            # 城市(City)\n",
    "                            \"宝鸡\", \"成都\", \"都江堰\", \"贵阳\", \"眉山\", \"乐山\", \"丽江\", \"六盘水\", \"洛阳\", \"绵阳\", \"南充\",\n",
    "                            \"内江\", \"彭州\", \"遂宁\",   \"万州\", \"西安\", \"咸阳\", \"玉溪\", \"遵义\",\n",
    "\n",
    "                            # 行政区(District)\n",
    "                            \"高新\", \"青白江\", \"青羊\", \"双流\",\n",
    "\n",
    "                            # 县(County)\n",
    "                            \"大邑\", \"户县\", \"华阳\", \"南部\", \"郫县\", \"仁寿\", \"资中\",\n",
    "\n",
    "                            # 其它(Other)\n",
    "                            \"淳化\", \"财经\", \"白云\", \"广场\",   \"红宝石\", \"海福城\", \"壕沟\",   \"华为\", \"虹祥\",   \"海逸\", \"锦华\",\n",
    "                            \"丽都\", \"丽苑\", \"苹果\", \"水池\",   \"蜀都\",   \"蜀汉\",   \"蜀泰\",   \"沙湾\", \"太升路\", \"图腾\", \"新城\",\n",
    "                            \"人民\", \"万达\", \"万国\", \"犀浦\",   \"西山\",   \"形象\",   \"新中路\", \"杨凌\", \"珠海路\", \"重龙\"]\n",
    "    # ----------------------------------------------\n",
    "    Copy_String_A = String_A.replace(\"苹果\", \"形象\").replace(\"苹果店\", \"形象\")\n",
    "    Copy_String_B = String_B.replace(\"苹果\", \"形象\").replace(\"苹果店\", \"形象\")\n",
    "    # ----------------------------------------------\n",
    "    List_Str_A:list = []\n",
    "    List_Str_B:list = []\n",
    "    List_Str_A_Length:int = 0\n",
    "    List_Str_B_Length:int = 0\n",
    "    # ----------------------------------------------\n",
    "    for Idx in range(0, len(Word_Of_Chinese)):\n",
    "        if (Word_Of_Chinese[Idx] in Copy_String_A): # -> Handle String A.\n",
    "            List_Str_A.append(Word_Of_Chinese[Idx])\n",
    "            # --------------------------------------\n",
    "            Copy_String_A = Copy_String_A.replace(Word_Of_Chinese[Idx], str(''))\n",
    "        # ------------------------------------------\n",
    "        if (Word_Of_Chinese[Idx] in Copy_String_B): # -> Handle String B.\n",
    "            List_Str_B.append(Word_Of_Chinese[Idx])\n",
    "            # --------------------------------------\n",
    "            Copy_String_B = Copy_String_B.replace(Word_Of_Chinese[Idx], str(''))\n",
    "    # ----------------------------------------------\n",
    "    for Word in Copy_String_A: List_Str_A.append(Word)\n",
    "    for Word in List_Str_A: List_Str_A_Length += len(Word) # -> Total of Characters Number.\n",
    "    for Word in Copy_String_B: List_Str_B.append(Word)\n",
    "    for Word in List_Str_B: List_Str_B_Length += len(Word) # -> Total of Characters Number.\n",
    "    # ----------------------------------------------\n",
    "    #print(List_Str_A, List_Str_B)\n",
    "    Matched_Char_Num:int = 0\n",
    "    # ----------------------------------------------\n",
    "    if (List_Str_A_Length >= List_Str_B_Length):\n",
    "        for Str in List_Str_B:\n",
    "            if (Str in List_Str_A): Matched_Char_Num += len(Str) # -> Number of Characters That Can be Matched.\n",
    "        # ------------------------------------------\n",
    "        return round(Matched_Char_Num / List_Str_A_Length, 4)\n",
    "    # ----------------------------------------------\n",
    "    if (List_Str_A_Length <  List_Str_B_Length):\n",
    "        for Str in List_Str_A:\n",
    "            if (Str in List_Str_B): Matched_Char_Num += len(Str) # -> Number of Characters That Can be Matched.\n",
    "        # ------------------------------------------\n",
    "        return round(Matched_Char_Num / List_Str_B_Length, 4)\n",
    "    # ----------------------------------------------\n",
    "    # End of Function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8754cbdf",
   "metadata": {},
   "outputs": [],
   "source": [
    "def PdFunc_Str_RegExp_Search(Obj:object, Pattern:str) -> object:\n",
    "\n",
    "    \"\"\"[Required] import re [Version 2.2.1]\"\"\"\n",
    "    if (type(Obj) is str):\n",
    "        \n",
    "        Result = re.search(Pattern, Obj)\n",
    "        # ------------------------------------------\n",
    "        if Result == None:\n",
    "            return None\n",
    "        if Result != None:\n",
    "            return Result.group()\n",
    "\n",
    "    else:\n",
    "\n",
    "        return Obj\n",
    "    # ----------------------------------------------\n",
    "    # Function End.\n",
    "\n",
    "def PdFunc_Str_RegExp_Findall(Obj:object, Pattern:str, ResIdx:int) -> object:\n",
    "\n",
    "    \"\"\"[Required] import re [Version 2.2.1]\"\"\"\n",
    "    if (type(Obj) is str):\n",
    "        \n",
    "        Result = re.findall(Pattern, Obj)\n",
    "        # ------------------------------------------\n",
    "        if (Result == []):\n",
    "            return None\n",
    "        if (Result != []) and ((ResIdx + 1) >  len(Result)):\n",
    "            return None\n",
    "        if (Result != []) and ((ResIdx + 1) <= len(Result)):\n",
    "            return Result[ResIdx]\n",
    "\n",
    "    else:\n",
    "\n",
    "        return Obj\n",
    "    # ----------------------------------------------\n",
    "    # Function End.\n",
    "\n",
    "def PdFunc_Str_RegExp_Split(Obj:object, Pattern:str) -> object:\n",
    "\n",
    "    \"\"\"[Required] import re [Version 2.2.1]\"\"\"\n",
    "    if (type(Obj) is str):\n",
    "        return re.split(Pattern, Obj)\n",
    "    else:\n",
    "        return Obj\n",
    "    # ----------------------------------------------\n",
    "    # Function End.\n",
    "    \n",
    "def PdFunc_Str_Replace(Obj:object, OldStr:str, NewStr:str) -> object:\n",
    "    \n",
    "    if (type(Obj) is str):\n",
    "        return Obj.replace(OldStr, NewStr)\n",
    "    else:\n",
    "        return Obj\n",
    "    # ----------------------------------------------\n",
    "    # Function End.\n",
    "\n",
    "def PdFunc_Judgement_Cell_Contains_List(DF:pandas.core.frame.DataFrame, FldName:str) -> bool:\n",
    "\n",
    "    \"\"\"[Required] import pandas [Version 1.4.1]\"\"\"\n",
    "    for Cell in DF[FldName]:\n",
    "        if type(Cell) is list:\n",
    "            return True\n",
    "    else:\n",
    "        return False\n",
    "    # ----------------------------------------------\n",
    "    # Function End."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8ba1287e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Docx GF Extract Content(Cry) Row By One Keyword.\n",
    "def Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path:str, Keyword:str):\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    ObjDocx = docx.Document(Docx_Path)\n",
    "    # ----------------------------------------------\n",
    "    for paragraph in ObjDocx.paragraphs:\n",
    "        if (Keyword in paragraph.text):\n",
    "            return paragraph.text\n",
    "    # ----------------------------------------------\n",
    "    # End of Function.\n",
    "\n",
    "# Docx GF Extract Content(Cry) Row By Two Keyword.\n",
    "def Docx_Extract_Cry_Row_By_Two_Keyword(Docx_Path:str, Keyword_1:str, Keyword_2:str):\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    ObjDocx = docx.Document(Docx_Path)\n",
    "    # ----------------------------------------------\n",
    "    for paragraph in ObjDocx.paragraphs:\n",
    "        if (Keyword_1 in paragraph.text) and (Keyword_2 in paragraph.text):\n",
    "            return paragraph.text\n",
    "    # ----------------------------------------------\n",
    "    # End of Function.\n",
    "\n",
    "# Docx GF Extract Content(Cry) Title.\n",
    "def Docx_Extract_Cry_Title(Docx_Path:str):\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    ObjDocx = docx.Document(Docx_Path)\n",
    "    # ----------------------------------------------\n",
    "    for index, paragraph in enumerate(ObjDocx.paragraphs):\n",
    "        #print(index, paragraph.text)\n",
    "        # ------------------------------------------\n",
    "        Judgement:int = 0\n",
    "        # ------------------------------------------\n",
    "        if (paragraph.alignment == docx.enum.text.WD_PARAGRAPH_ALIGNMENT.CENTER): Judgement += 1\n",
    "        # ------------------------------------------\n",
    "        if (len(paragraph.text) > 0): Judgement += 1\n",
    "        # ------------------------------------------\n",
    "        if (Judgement == 2): return paragraph.text\n",
    "    # ----------------------------------------------\n",
    "    # End of Function.\n",
    "\n",
    "# Docx GF Extract Table All.\n",
    "def Docx_Extract_Table_All(Docx_Path:str, Table_No:int):\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    ObjDocx = docx.Document(Docx_Path)\n",
    "    # ----------------------------------------------\n",
    "    if (Table_No >= len(ObjDocx.tables)): # -> Table number exceeds index.\n",
    "        # ------------------------------------------\n",
    "        return None\n",
    "    # ----------------------------------------------\n",
    "    Table_Rows_Num = len(ObjDocx.tables[Table_No].rows)\n",
    "    Table_Cols_Num = len(ObjDocx.tables[Table_No].columns)\n",
    "    # ----------------------------------------------\n",
    "    Table_All:list = []\n",
    "    Table_Row:list = []\n",
    "    # ----------------------------------------------\n",
    "    for RowIdx in range(0, Table_Rows_Num): # -> Extract table data.\n",
    "        for ColIdx in range(0, Table_Cols_Num):\n",
    "            try:\n",
    "                Table_Row.append(ObjDocx.tables[Table_No].cell(RowIdx, ColIdx).paragraphs[0].text)\n",
    "            except IndexError: # -> # IndexError: cell index [x] is out of range.\n",
    "                Table_Row.append(\"Null\")\n",
    "        # ------------------------------------------\n",
    "        Table_All.append(Table_Row.copy())\n",
    "        Table_Row.clear()\n",
    "    # ----------------------------------------------\n",
    "    return Table_All\n",
    "\n",
    "# Docx GF Review Field Stored By Row or Column.\n",
    "def Docx_Review_Field_Stored_By_Row_Or_Column(Docx_Path:str, Table_No:int, FldName:str, FldCryHint:str) -> str:\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    Table_All:list = Docx_Extract_Table_All(Docx_Path, Table_No)\n",
    "    # ----------------------------------------------\n",
    "    TableRowsNum:int = None\n",
    "    TableColsNum:int = None\n",
    "    # ----------------------------------------------\n",
    "    if (Table_All == None):\n",
    "        return \"Empty\" # -> If Table is Empty.\n",
    "    else:\n",
    "        TableRowsNum = len(Table_All)\n",
    "        TableColsNum = len(Table_All[0])\n",
    "    # ----------------------------------------------\n",
    "    \n",
    "    # Condition Judgement - Start.\n",
    "    if   (TableRowsNum == 1):\n",
    "        \n",
    "        return \"Stored By Horizontal\"\n",
    "    \n",
    "    elif (TableRowsNum == 2) and (TableColsNum == 1):\n",
    "    \n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[1][X]): return \"Stored By Vertical\"\n",
    "    \n",
    "    elif (TableRowsNum == 2) and (TableColsNum >= 2):\n",
    "        \n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[1][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for Y in range(0, len(Table_All)):       # -> Finding in Table 1st Col.\n",
    "            if (FldName in Table_All[Y][0]) and (FldCryHint in Table_All[Y][1]): return \"Stored By Horizontal\"\n",
    "    \n",
    "    elif (TableRowsNum >= 3) and (TableColsNum == 1):\n",
    "    \n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[1][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row, Hint for Cross Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[2][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for X in range(0, len(Table_All[1])):    # -> Finding in Table 2th Row.\n",
    "            if (FldName in Table_All[1][X]) and (FldCryHint in Table_All[2][X]): return \"Stored By Vertical\"\n",
    "    \n",
    "    elif (TableRowsNum >= 3) and (TableColsNum >= 2):\n",
    "    \n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[1][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for X in range(0, len(Table_All[0])):    # -> Finding in Table 1st Row, Hint for Cross Row.\n",
    "            if (FldName in Table_All[0][X]) and (FldCryHint in Table_All[2][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for X in range(0, len(Table_All[1])):    # -> Finding in Table 2th Row.\n",
    "            if (FldName in Table_All[1][X]) and (FldCryHint in Table_All[2][X]): return \"Stored By Vertical\"\n",
    "        # ------------------------------------------\n",
    "        for Y in range(0, len(Table_All)):       # -> Finding in Table 1st Col.\n",
    "            if (FldName in Table_All[Y][0]) and (FldCryHint in Table_All[Y][1]): return \"Stored By Horizontal\"\n",
    "    # Condition Judgement - Ends.\n",
    "\n",
    "    # ----------------------------------------------\n",
    "    return \"Error\"\n",
    "\n",
    "# Docx GF Extract Table Series By Field Name.\n",
    "def Docx_Extract_Table_Series_By_FldName(Docx_Path:str, Table_No:int, FldName:str, FldCryHint:str) -> list:\n",
    "\n",
    "    \"\"\"[Required] import docx [Version 0.7.4]\"\"\"\n",
    "    # ----------------------------------------------\n",
    "    Table_All:list = Docx_Extract_Table_All(Docx_Path, Table_No)\n",
    "    # ----------------------------------------------\n",
    "    if (Table_All is None): return list([]) # -> Return empty list.\n",
    "    # ----------------------------------------------\n",
    "    Field_Stored_By_Row_Or_Column:str = Docx_Review_Field_Stored_By_Row_Or_Column(Docx_Path, Table_No, FldName, FldCryHint)\n",
    "    # ----------------------------------------------\n",
    "\n",
    "    # Condition Judgement - Start.\n",
    "    if   (Field_Stored_By_Row_Or_Column == \"Stored By Horizontal\"):\n",
    "        \n",
    "        for Row in Table_All:\n",
    "            if (FldName in Row):\n",
    "                return Row\n",
    "    \n",
    "    elif (Field_Stored_By_Row_Or_Column == \"Stored By Vertical\"):\n",
    "\n",
    "        Table_All_Transpose:list = []\n",
    "        Table_Col:list = []\n",
    "        # ------------------------------------------\n",
    "        for ColIdx in range(0, len(Table_All[0])): # -> Row and column transposition.\n",
    "            for RowIdx in range(0, len(Table_All)):\n",
    "                Table_Col.append(Table_All[RowIdx][ColIdx])\n",
    "            # --------------------------------------\n",
    "            Table_All_Transpose.append(Table_Col.copy())\n",
    "            Table_Col.clear()\n",
    "        # ------------------------------------------\n",
    "        for Col in Table_All_Transpose:\n",
    "            if (FldName in Col):\n",
    "                return Col\n",
    "    # Condition Judgement - Ends.\n",
    "\n",
    "    # ----------------------------------------------\n",
    "    return list([]) # -> Return empty list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f8eba238",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   政策标题  政策门店  政策目标  政策时间  政策其它\n",
       "0  None  None  None  None  None"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\"政策标题\":[None],\n",
    "                   \"政策门店\":[None],\n",
    "                   \"政策目标\":[None],\n",
    "                   \"政策时间\":[None],\n",
    "                   \"政策其它\":[None]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "93175843",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部11月双流万达守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部2023年8月眉山万达第五轮守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部2月突击门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部6月突击门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部7月眉山万达守卫政策 (1).doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部7月眉山万达守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部7月眉山万达守卫政策补充.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部7月突击门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部8月眉山万达守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部8月眉山万达第四轮守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部七月第二轮突击门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部四月突击门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部阅兵门店守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部阅兵门店第二轮守卫政策.doc\n",
      "C:\\GF-Datas\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\\零售三部集团对标门店守卫政策.doc\n"
     ]
    }
   ],
   "source": [
    "Root_Path = \"C:\\\\GF-Datas\\\\DOC文件_讯捷集团_政策文件(所有)_2022-12-20至2023-12-20\"\n",
    "\n",
    "for DocFile in os.listdir(Root_Path):\n",
    "    Docx_Path = \"%s\\\\%s\" % (Root_Path, DocFile)\n",
    "    # ----------------------------------------------\n",
    "    try:\n",
    "        Policy_Title:list    = [Docx_Extract_Cry_Title(Docx_Path)]\n",
    "        # ------------------------------------------\n",
    "        Policy_Store:list    = [Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"政策门店\"),\n",
    "                                Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"政策店面\"),\n",
    "                                Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"政策对象\"),\n",
    "                                Docx_Extract_Table_Series_By_FldName(Docx_Path, 0, \"门店\", \"苹果\"),\n",
    "                                Docx_Extract_Table_Series_By_FldName(Docx_Path, 0, \"门店\", \"形象\"),\n",
    "                                Docx_Extract_Table_Series_By_FldName(Docx_Path, 0, \"门店\", \"华为\")]\n",
    "        # ------------------------------------------\n",
    "        Policy_Target:list   = [None,\n",
    "                                Docx_Extract_Table_Series_By_FldName(Docx_Path, 0, \"任务\", \"0\"),\n",
    "                                Docx_Extract_Table_Series_By_FldName(Docx_Path, 0, \"任务\", \"8\")]\n",
    "        # ------------------------------------------\n",
    "        Policy_Datetime:list = [Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"时间\"),\n",
    "                                Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"政策时间\"),\n",
    "                                Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"守卫时间\"),\n",
    "                                Docx_Extract_Cry_Row_By_One_Keyword(Docx_Path, \"活动时间\"),\n",
    "                                Docx_Extract_Cry_Row_By_Two_Keyword(Docx_Path, \"月\", \"日\")]\n",
    "        # ------------------------------------------\n",
    "        Policy_Other:list    = []\n",
    "        # ------------------------------------------\n",
    "        for Element_A in Policy_Store:\n",
    "            for Element_B in Policy_Target:\n",
    "                # Judgement Start.\n",
    "                if (type(Element_A) is list) and (type(Element_B) is list):\n",
    "                    if (type(Element_A) != []) and (type(Element_B) != []):\n",
    "                        if (len(Element_A) == len(Element_B)):\n",
    "                            Policy_Other.append([(A, B) for A, B in zip(Element_A, Element_B)])\n",
    "                # Judgement Ends.\n",
    "        # ------------------------------------------\n",
    "        Row:dict = {\"政策标题\": Policy_Title,\n",
    "                    \"政策门店\": Policy_Store,\n",
    "                    \"政策目标\": Policy_Target,\n",
    "                    \"政策时间\": Policy_Datetime,\n",
    "                    \"政策其它\": Policy_Other}\n",
    "        # ------------------------------------------\n",
    "        Pd_Row = pd.Series(Row) # -> 创建 Series 对象。\n",
    "        # ------------------------------------------\n",
    "        df = df.append(Pd_Row, ignore_index=True) # -> 使用 append 方法将 Series 对象添加到 DataFrame 中。\n",
    "\n",
    "    # KeyError: \"no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection\".\n",
    "    except KeyError:\n",
    "        print(Docx_Path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "5902fd67",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "      <th>开始时间</th>\n",
       "      <th>结束时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>团结苹果</td>\n",
       "      <td>11500</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(团结苹果, 11500)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>城市立方苹果</td>\n",
       "      <td>17000</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(城市立方苹果, 17000)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>宝鸡电子苹果</td>\n",
       "      <td>13000</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(宝鸡电子苹果, 13000)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>财富苹果</td>\n",
       "      <td>9800</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(财富苹果, 9800)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>南大街苹果</td>\n",
       "      <td>8800</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(南大街苹果, 8800)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>6000</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川龙泉中街形象店, 6000)</td>\n",
       "      <td>2023年11月22日</td>\n",
       "      <td>2023年12月12日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>6000</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川新都繁清形象店, 6000)</td>\n",
       "      <td>2023年11月22日</td>\n",
       "      <td>2023年12月12日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀都苹果</td>\n",
       "      <td>7500</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀都苹果, 7500)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀泰苹果</td>\n",
       "      <td>6800</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀泰苹果, 6800)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>桂东苹果</td>\n",
       "      <td>9100</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(桂东苹果, 9100)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>193 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           政策标题       政策门店   政策目标                                 政策时间  \\\n",
       "0    西安门店守卫政策申请       团结苹果  11500                     守卫时间：2月19日-2月28日   \n",
       "1    西安门店守卫政策申请     城市立方苹果  17000                     守卫时间：2月19日-2月28日   \n",
       "2    西安门店守卫政策申请     宝鸡电子苹果  13000                     守卫时间：2月19日-2月28日   \n",
       "3    西安门店守卫政策申请       财富苹果   9800                     守卫时间：2月19日-2月28日   \n",
       "4    西安门店守卫政策申请      南大街苹果   8800                     守卫时间：2月19日-2月28日   \n",
       "..          ...        ...    ...                                  ...   \n",
       "188     零售四中心四部  四川龙泉中街形象店   6000       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "189     零售四中心四部  四川新都繁清形象店   6000       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "190     零售四中心四部       蜀都苹果   7500  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "191     零售四中心四部       蜀泰苹果   6800  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "192     零售四中心四部       桂东苹果   9100  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "\n",
       "                  政策其它         开始时间         结束时间  \n",
       "0        (团结苹果, 11500)   2023年2月19日   2023年2月28日  \n",
       "1      (城市立方苹果, 17000)   2023年2月19日   2023年2月28日  \n",
       "2      (宝鸡电子苹果, 13000)   2023年2月19日   2023年2月28日  \n",
       "3         (财富苹果, 9800)   2023年2月19日   2023年2月28日  \n",
       "4        (南大街苹果, 8800)   2023年2月19日   2023年2月28日  \n",
       "..                 ...          ...          ...  \n",
       "188  (四川龙泉中街形象店, 6000)  2023年11月22日  2023年12月12日  \n",
       "189  (四川新都繁清形象店, 6000)  2023年11月22日  2023年12月12日  \n",
       "190       (蜀都苹果, 7500)   2023年12月1日  2023年12月14日  \n",
       "191       (蜀泰苹果, 6800)   2023年12月1日  2023年12月14日  \n",
       "192       (桂东苹果, 9100)   2023年12月1日  2023年12月14日  \n",
       "\n",
       "[193 rows x 7 columns]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Explode = df.copy()\n",
    "# ----------------------------------------------\n",
    "while (PdFunc_Judgement_Cell_Contains_List(Explode, \"政策标题\") == True): Explode = Explode.explode(\"政策标题\")\n",
    "while (PdFunc_Judgement_Cell_Contains_List(Explode, \"政策门店\") == True): Explode = Explode.explode(\"政策门店\")\n",
    "#while (PdFunc_Judgement_Cell_Contains_List(Explode, \"政策标题\") == True): Explode = Explode.explode(\"政策目标\")\n",
    "Explode = Explode.explode(\"政策目标\")\n",
    "while (PdFunc_Judgement_Cell_Contains_List(Explode, \"政策时间\") == True): Explode = Explode.explode(\"政策时间\")\n",
    "while (PdFunc_Judgement_Cell_Contains_List(Explode, \"政策其它\") == True): Explode = Explode.explode(\"政策其它\")\n",
    "# ----------------------------------------------\n",
    "#Explode = Explode.drop_duplicates([\"政策门店\", \"政策目标\", \"政策时间\", \"政策其它\"])\n",
    "# ----------------------------------------------\n",
    "Explode[\"政策门店\"] = Explode[\"政策门店\"].apply(lambda x: PdFunc_Str_Replace(x, '。', str('')))\n",
    "Explode[\"政策时间\"] = Explode[\"政策时间\"].apply(lambda x: PdFunc_Str_Replace(x, '。', str('')))\n",
    "## ----------------------------------------------\n",
    "Explode[\"政策门店\"] = Explode[\"政策门店\"].apply(lambda x: PdFunc_Str_RegExp_Split(x, \"，|、|：|。|/\"))\n",
    "## ----------------------------------------------\n",
    "Explode = Explode.explode(\"政策门店\")\n",
    "Explode = Explode.explode(\"政策时间\")\n",
    "# ----------------------------------------------\n",
    "\n",
    "# 元组处理。\n",
    "Explode = Explode.reset_index(drop=True)\n",
    "# ----------------------------------------------\n",
    "for RowIdx in Explode.index:\n",
    "    Element = Explode.loc[RowIdx, \"政策其它\"]\n",
    "    # ------------------------------------------\n",
    "    if (type(Element) is tuple): Explode.loc[RowIdx, \"政策门店\"] = Element[0]\n",
    "    if (type(Element) is tuple): Explode.loc[RowIdx, \"政策目标\"] = Element[1]\n",
    "\n",
    "# 时间处理。\n",
    "# ----------------------------------------------\n",
    "Explode[\"Memo1\"] = None\n",
    "Explode[\"Memo2\"] = None\n",
    "Explode = Explode.reset_index(drop=True)\n",
    "# ----------------------------------------------\n",
    "Explode[\"Memo1\"] = Explode[\"政策时间\"].apply(lambda x: PdFunc_Str_RegExp_Findall(x, \"\\d{1,4}年\\d{1,2}月\\d{1,2}日\", 0))\n",
    "Explode[\"Memo2\"] = Explode[\"政策时间\"].apply(lambda x: PdFunc_Str_RegExp_Findall(x, \"\\d{1,4}年\\d{1,2}月\\d{1,2}日\", 1))\n",
    "# ----------------------------------------------\n",
    "for RowIdx in Explode.index: # -> 查找 \"XX月XX日\" 和 \"~XX日\" 日期。\n",
    "    Pattern = \"\\d{1,2}月\\d{1,2}日|\\~\\d{1,2}日\"\n",
    "    # ------------------------------------------\n",
    "    if Explode.loc[RowIdx, \"Memo1\"] == None:\n",
    "        Explode.loc[RowIdx, \"Memo1\"] = PdFunc_Str_RegExp_Findall(Explode.loc[RowIdx, \"政策时间\"], Pattern, 0)\n",
    "    if Explode.loc[RowIdx, \"Memo2\"] == None:\n",
    "        Explode.loc[RowIdx, \"Memo2\"] = PdFunc_Str_RegExp_Findall(Explode.loc[RowIdx, \"政策时间\"], Pattern, 1)\n",
    "# ----------------------------------------------\n",
    "for RowIdx in Explode.index: # -> 补全月份。\n",
    "    Element = Explode.loc[RowIdx, \"Memo2\"]\n",
    "    # ------------------------------------------\n",
    "    if (Element != None) and ('~' in Element) and (\"月\" not in Element):\n",
    "        Month = PdFunc_Str_RegExp_Search(Explode.loc[RowIdx, \"Memo1\"], \"\\d{1,2}月\")\n",
    "        # --------------------------------------\n",
    "        Explode.loc[RowIdx, \"Memo2\"] = Element.replace('~', Month)\n",
    "# ----------------------------------------------\n",
    "for RowIdx in Explode.index: # -> 补全年份。\n",
    "    Element1 = Explode.loc[RowIdx, \"Memo1\"]\n",
    "    Element2 = Explode.loc[RowIdx, \"Memo2\"]\n",
    "    # ------------------------------------------\n",
    "    if (Element1 != None) and (\"2023年\" not in Element1): Explode.loc[RowIdx, \"Memo1\"] = \"%s%s\" % (\"2023年\", Element1)\n",
    "    if (Element2 != None) and (\"2023年\" not in Element2): Explode.loc[RowIdx, \"Memo2\"] = \"%s%s\" % (\"2023年\", Element2)\n",
    "\n",
    "# 数据筛选。\n",
    "# ----------------------------------------------\n",
    "Explode = Explode[Explode[\"政策标题\"].isna() == False]\n",
    "# ----------------------------------------------\n",
    "Explode = Explode[Explode[\"政策门店\"].isna() == False]\n",
    "Explode = Explode[Explode[\"政策门店\"] != str('')]\n",
    "Explode = Explode[Explode[\"政策门店\"] != \"政策门店\"]\n",
    "Explode = Explode[Explode[\"政策门店\"] != \"政策店面\"]\n",
    "Explode = Explode[Explode[\"政策门店\"] != \"政策对象\"]\n",
    "Explode = Explode[Explode[\"政策门店\"] != \"门店\"]\n",
    "# ----------------------------------------------\n",
    "Explode = Explode[Explode[\"政策时间\"].isna() == False]\n",
    "Explode = Explode[Explode[\"政策时间\"] != \"政策时间\"]\n",
    "Explode = Explode[Explode[\"政策时间\"] != \"守卫时间\"]\n",
    "Explode = Explode[Explode[\"政策时间\"] != \"活动时间\"]\n",
    "# ----------------------------------------------\n",
    "Explode = Explode[Explode[\"政策目标\"].isna() == False]\n",
    "# ----------------------------------------------\n",
    "Explode = Explode.drop_duplicates([\"政策门店\", \"政策其它\", \"Memo1\", \"Memo2\"]).reset_index(drop=True)\n",
    "Explode = Explode.rename(columns={\"Memo1\":\"开始时间\", \"Memo2\":\"结束时间\"})\n",
    "# ----------------------------------------------\n",
    "Explode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "f0055611",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Explode.to_excel(\"./Test.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "187e5007",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "      <th>开始时间</th>\n",
       "      <th>结束时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>团结苹果</td>\n",
       "      <td>11500.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(团结苹果, 11500)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>城市立方苹果</td>\n",
       "      <td>17000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(城市立方苹果, 17000)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>宝鸡电子苹果</td>\n",
       "      <td>13000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(宝鸡电子苹果, 13000)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>财富苹果</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(财富苹果, 9800)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>南大街苹果</td>\n",
       "      <td>8800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(南大街苹果, 8800)</td>\n",
       "      <td>2023年2月19日</td>\n",
       "      <td>2023年2月28日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川龙泉中街形象店, 6000)</td>\n",
       "      <td>2023年11月22日</td>\n",
       "      <td>2023年12月12日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川新都繁清形象店, 6000)</td>\n",
       "      <td>2023年11月22日</td>\n",
       "      <td>2023年12月12日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀都苹果</td>\n",
       "      <td>7500.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀都苹果, 7500)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀泰苹果</td>\n",
       "      <td>6800.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀泰苹果, 6800)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>桂东苹果</td>\n",
       "      <td>9100.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(桂东苹果, 9100)</td>\n",
       "      <td>2023年12月1日</td>\n",
       "      <td>2023年12月14日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>193 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           政策标题       政策门店     政策目标                                 政策时间  \\\n",
       "0    西安门店守卫政策申请       团结苹果  11500.0                     守卫时间：2月19日-2月28日   \n",
       "1    西安门店守卫政策申请     城市立方苹果  17000.0                     守卫时间：2月19日-2月28日   \n",
       "2    西安门店守卫政策申请     宝鸡电子苹果  13000.0                     守卫时间：2月19日-2月28日   \n",
       "3    西安门店守卫政策申请       财富苹果   9800.0                     守卫时间：2月19日-2月28日   \n",
       "4    西安门店守卫政策申请      南大街苹果   8800.0                     守卫时间：2月19日-2月28日   \n",
       "..          ...        ...      ...                                  ...   \n",
       "188     零售四中心四部  四川龙泉中街形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "189     零售四中心四部  四川新都繁清形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "190     零售四中心四部       蜀都苹果   7500.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "191     零售四中心四部       蜀泰苹果   6800.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "192     零售四中心四部       桂东苹果   9100.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "\n",
       "                  政策其它         开始时间         结束时间  \n",
       "0        (团结苹果, 11500)   2023年2月19日   2023年2月28日  \n",
       "1      (城市立方苹果, 17000)   2023年2月19日   2023年2月28日  \n",
       "2      (宝鸡电子苹果, 13000)   2023年2月19日   2023年2月28日  \n",
       "3         (财富苹果, 9800)   2023年2月19日   2023年2月28日  \n",
       "4        (南大街苹果, 8800)   2023年2月19日   2023年2月28日  \n",
       "..                 ...          ...          ...  \n",
       "188  (四川龙泉中街形象店, 6000)  2023年11月22日  2023年12月12日  \n",
       "189  (四川新都繁清形象店, 6000)  2023年11月22日  2023年12月12日  \n",
       "190       (蜀都苹果, 7500)   2023年12月1日  2023年12月14日  \n",
       "191       (蜀泰苹果, 6800)   2023年12月1日  2023年12月14日  \n",
       "192       (桂东苹果, 9100)   2023年12月1日  2023年12月14日  \n",
       "\n",
       "[193 rows x 7 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for Idx in Explode.index:\n",
    "    Obj = Explode.loc[Idx, \"政策目标\"]\n",
    "    # ------------------------------------------\n",
    "    try:\n",
    "        Explode.loc[Idx, \"政策目标\"] = float(Obj)\n",
    "    except ValueError: # -> could not convert string to float: ''.\n",
    "        Explode.loc[Idx, \"政策目标\"] = None\n",
    "    except TypeError: # -> float() argument must be a string or a number, not 'list'.\n",
    "        Explode.loc[Idx, \"政策目标\"] = None\n",
    "# ----------------------------------------------\n",
    "Explode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "23fa67c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "      <th>开始时间</th>\n",
       "      <th>结束时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>团结苹果</td>\n",
       "      <td>11500.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(团结苹果, 11500)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>城市立方苹果</td>\n",
       "      <td>17000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(城市立方苹果, 17000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>宝鸡电子苹果</td>\n",
       "      <td>13000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(宝鸡电子苹果, 13000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>财富苹果</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(财富苹果, 9800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>南大街苹果</td>\n",
       "      <td>8800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(南大街苹果, 8800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川龙泉中街形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川新都繁清形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀都苹果</td>\n",
       "      <td>7500.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀都苹果, 7500)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀泰苹果</td>\n",
       "      <td>6800.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀泰苹果, 6800)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>桂东苹果</td>\n",
       "      <td>9100.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(桂东苹果, 9100)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>193 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           政策标题       政策门店     政策目标                                 政策时间  \\\n",
       "0    西安门店守卫政策申请       团结苹果  11500.0                     守卫时间：2月19日-2月28日   \n",
       "1    西安门店守卫政策申请     城市立方苹果  17000.0                     守卫时间：2月19日-2月28日   \n",
       "2    西安门店守卫政策申请     宝鸡电子苹果  13000.0                     守卫时间：2月19日-2月28日   \n",
       "3    西安门店守卫政策申请       财富苹果   9800.0                     守卫时间：2月19日-2月28日   \n",
       "4    西安门店守卫政策申请      南大街苹果   8800.0                     守卫时间：2月19日-2月28日   \n",
       "..          ...        ...      ...                                  ...   \n",
       "188     零售四中心四部  四川龙泉中街形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "189     零售四中心四部  四川新都繁清形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "190     零售四中心四部       蜀都苹果   7500.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "191     零售四中心四部       蜀泰苹果   6800.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "192     零售四中心四部       桂东苹果   9100.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "\n",
       "                  政策其它        开始时间        结束时间  \n",
       "0        (团结苹果, 11500)  2023-02-19  2023-02-28  \n",
       "1      (城市立方苹果, 17000)  2023-02-19  2023-02-28  \n",
       "2      (宝鸡电子苹果, 13000)  2023-02-19  2023-02-28  \n",
       "3         (财富苹果, 9800)  2023-02-19  2023-02-28  \n",
       "4        (南大街苹果, 8800)  2023-02-19  2023-02-28  \n",
       "..                 ...         ...         ...  \n",
       "188  (四川龙泉中街形象店, 6000)  2023-11-22  2023-12-12  \n",
       "189  (四川新都繁清形象店, 6000)  2023-11-22  2023-12-12  \n",
       "190       (蜀都苹果, 7500)  2023-12-01  2023-12-14  \n",
       "191       (蜀泰苹果, 6800)  2023-12-01  2023-12-14  \n",
       "192       (桂东苹果, 9100)  2023-12-01  2023-12-14  \n",
       "\n",
       "[193 rows x 7 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PDF_Dst = Explode[Explode[\"政策目标\"] != None].copy()\n",
    "PDF_Src = pd.read_excel(\"C:\\\\GF-Datas\\\\政策门店(1).xlsx\", sheet_name=\"Sheet2\")\n",
    "# ----------------------------------------------\n",
    "PDF_Dst[\"政策门店\"] = PDF_Dst[\"政策门店\"].astype(\"string\")\n",
    "# ----------------------------------------------\n",
    "PDF_Dst[\"开始时间\"] = PDF_Dst[\"开始时间\"].apply(lambda x: x.replace('年', '-')\\\n",
    "                                                            .replace('月', '-')\\\n",
    "                                                            .replace('日', '-')\\\n",
    "                                                            if x != None else None)\n",
    "PDF_Dst[\"结束时间\"] = PDF_Dst[\"结束时间\"].apply(lambda x: x.replace('年', '-')\\\n",
    "                                                            .replace('月', '-')\\\n",
    "                                                            .replace('日', '-')\\\n",
    "                                                            if x != None else None)\n",
    "# ----------------------------------------------\n",
    "PDF_Dst[\"开始时间\"] = PDF_Dst[\"开始时间\"].astype(\"datetime64[ns]\").dt.strftime(\"%Y-%m-%d\")\n",
    "PDF_Dst[\"结束时间\"] = PDF_Dst[\"结束时间\"].astype(\"datetime64[ns]\").dt.strftime(\"%Y-%m-%d\")\n",
    "# ----------------------------------------------\n",
    "PDF_Src[\"门店全称\"] = PDF_Src[\"门店全称\"].astype(\"string\")\n",
    "PDF_Src[\"门店简称\"] = PDF_Src[\"门店简称\"].astype(\"string\")\n",
    "PDF_Src[\"门店全称\"] = PDF_Src[\"门店全称\"].fillna(value=\"Null\")\n",
    "PDF_Src[\"门店简称\"] = PDF_Src[\"门店简称\"].fillna(value=\"Null\")\n",
    "# ----------------------------------------------\n",
    "PDF_Dst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "e21aa5ff",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "      <th>开始时间</th>\n",
       "      <th>结束时间</th>\n",
       "      <th>门店全称</th>\n",
       "      <th>匹配行号</th>\n",
       "      <th>匹配程度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>团结苹果</td>\n",
       "      <td>11500.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(团结苹果, 11500)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西咸阳团结形象店</td>\n",
       "      <td>83</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>城市立方苹果</td>\n",
       "      <td>17000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(城市立方苹果, 17000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西西安城市立方形象店</td>\n",
       "      <td>58</td>\n",
       "      <td>0.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>宝鸡电子苹果</td>\n",
       "      <td>13000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(宝鸡电子苹果, 13000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西宝鸡电子大厦形象店</td>\n",
       "      <td>45</td>\n",
       "      <td>0.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>财富苹果</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(财富苹果, 9800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>四川成都财富形象店</td>\n",
       "      <td>97</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>南大街苹果</td>\n",
       "      <td>8800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(南大街苹果, 8800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>四川温江大南街形象店</td>\n",
       "      <td>182</td>\n",
       "      <td>0.7143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川龙泉中街形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>146</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川新都繁清形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>186</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀都苹果</td>\n",
       "      <td>7500.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀都苹果, 7500)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>四川成都蜀都形象店</td>\n",
       "      <td>112</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀泰苹果</td>\n",
       "      <td>6800.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀泰苹果, 6800)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>四川成都蜀泰形象店</td>\n",
       "      <td>116</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>桂东苹果</td>\n",
       "      <td>9100.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(桂东苹果, 9100)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>重庆万州形象店</td>\n",
       "      <td>272</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>193 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           政策标题       政策门店     政策目标                                 政策时间  \\\n",
       "0    西安门店守卫政策申请       团结苹果  11500.0                     守卫时间：2月19日-2月28日   \n",
       "1    西安门店守卫政策申请     城市立方苹果  17000.0                     守卫时间：2月19日-2月28日   \n",
       "2    西安门店守卫政策申请     宝鸡电子苹果  13000.0                     守卫时间：2月19日-2月28日   \n",
       "3    西安门店守卫政策申请       财富苹果   9800.0                     守卫时间：2月19日-2月28日   \n",
       "4    西安门店守卫政策申请      南大街苹果   8800.0                     守卫时间：2月19日-2月28日   \n",
       "..          ...        ...      ...                                  ...   \n",
       "188     零售四中心四部  四川龙泉中街形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "189     零售四中心四部  四川新都繁清形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "190     零售四中心四部       蜀都苹果   7500.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "191     零售四中心四部       蜀泰苹果   6800.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "192     零售四中心四部       桂东苹果   9100.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "\n",
       "                  政策其它        开始时间        结束时间         门店全称 匹配行号    匹配程度  \n",
       "0        (团结苹果, 11500)  2023-02-19  2023-02-28    陕西咸阳团结形象店   83  0.6667  \n",
       "1      (城市立方苹果, 17000)  2023-02-19  2023-02-28  陕西西安城市立方形象店   58    0.75  \n",
       "2      (宝鸡电子苹果, 13000)  2023-02-19  2023-02-28  陕西宝鸡电子大厦形象店   45    0.75  \n",
       "3         (财富苹果, 9800)  2023-02-19  2023-02-28    四川成都财富形象店   97  0.6667  \n",
       "4        (南大街苹果, 8800)  2023-02-19  2023-02-28   四川温江大南街形象店  182  0.7143  \n",
       "..                 ...         ...         ...          ...  ...     ...  \n",
       "188  (四川龙泉中街形象店, 6000)  2023-11-22  2023-12-12    四川龙泉中街形象店  146     1.0  \n",
       "189  (四川新都繁清形象店, 6000)  2023-11-22  2023-12-12    四川新都繁清形象店  186     1.0  \n",
       "190       (蜀都苹果, 7500)  2023-12-01  2023-12-14    四川成都蜀都形象店  112  0.6667  \n",
       "191       (蜀泰苹果, 6800)  2023-12-01  2023-12-14    四川成都蜀泰形象店  116     1.0  \n",
       "192       (桂东苹果, 9100)  2023-12-01  2023-12-14      重庆万州形象店  272     0.5  \n",
       "\n",
       "[193 rows x 10 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PDF_Dst[\"门店全称\"] = None\n",
    "PDF_Dst[\"匹配行号\"] = None\n",
    "PDF_Dst[\"匹配程度\"] = None\n",
    "# ----------------------------------------------\n",
    "for Left_Idx in PDF_Dst.index:\n",
    "    Left_Store_Name = PDF_Dst.loc[Left_Idx, \"政策门店\"]\n",
    "    for Right_Idx in PDF_Src.index:\n",
    "        Right_Store_Name = PDF_Src.loc[Right_Idx, \"门店简称\"]\n",
    "        # --------------------------------------\n",
    "        Accuracy = StrFunc_Two_String_Similarity(Left_Store_Name, Right_Store_Name)\n",
    "        # --------------------------------------\n",
    "        if (PDF_Dst.loc[Left_Idx, \"匹配行号\"] == None) or (Accuracy >= PDF_Dst.loc[Left_Idx, \"匹配程度\"]):\n",
    "            PDF_Dst.loc[Left_Idx, \"匹配行号\"] = Right_Idx\n",
    "            PDF_Dst.loc[Left_Idx, \"匹配程度\"] = Accuracy\n",
    "\n",
    "for Left_Idx in PDF_Dst.index:\n",
    "    Left_Store_Name = PDF_Dst.loc[Left_Idx, \"政策门店\"]\n",
    "    for Right_Idx in PDF_Src.index:\n",
    "        Right_Store_Name = PDF_Src.loc[Right_Idx, \"门店全称\"]\n",
    "        # --------------------------------------\n",
    "        Accuracy = StrFunc_Two_String_Similarity(Left_Store_Name, Right_Store_Name)\n",
    "        # --------------------------------------\n",
    "        if (PDF_Dst.loc[Left_Idx, \"匹配行号\"] == None) or (Accuracy >= PDF_Dst.loc[Left_Idx, \"匹配程度\"]):\n",
    "            PDF_Dst.loc[Left_Idx, \"匹配行号\"] = Right_Idx\n",
    "            PDF_Dst.loc[Left_Idx, \"匹配程度\"] = Accuracy\n",
    "\n",
    "for Idx in PDF_Dst.index:\n",
    "    Matched_Row_Num = PDF_Dst.loc[Idx, \"匹配行号\"]\n",
    "    # ------------------------------------------\n",
    "    PDF_Dst.loc[Idx, \"门店全称\"] = PDF_Src.loc[Matched_Row_Num, \"门店全称\"]\n",
    "# ----------------------------------------------\n",
    "PDF_Dst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "d9e64187",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>政策标题</th>\n",
       "      <th>政策门店</th>\n",
       "      <th>政策目标</th>\n",
       "      <th>政策时间</th>\n",
       "      <th>政策其它</th>\n",
       "      <th>开始时间</th>\n",
       "      <th>结束时间</th>\n",
       "      <th>门店全称</th>\n",
       "      <th>匹配行号</th>\n",
       "      <th>匹配程度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>团结苹果</td>\n",
       "      <td>11500.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(团结苹果, 11500)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西咸阳团结形象店</td>\n",
       "      <td>83</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>城市立方苹果</td>\n",
       "      <td>17000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(城市立方苹果, 17000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西西安城市立方形象店</td>\n",
       "      <td>58</td>\n",
       "      <td>0.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>宝鸡电子苹果</td>\n",
       "      <td>13000.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(宝鸡电子苹果, 13000)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>陕西宝鸡电子大厦形象店</td>\n",
       "      <td>45</td>\n",
       "      <td>0.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>财富苹果</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(财富苹果, 9800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>四川成都财富形象店</td>\n",
       "      <td>97</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西安门店守卫政策申请</td>\n",
       "      <td>南大街苹果</td>\n",
       "      <td>8800.0</td>\n",
       "      <td>守卫时间：2月19日-2月28日</td>\n",
       "      <td>(南大街苹果, 8800)</td>\n",
       "      <td>2023-02-19</td>\n",
       "      <td>2023-02-28</td>\n",
       "      <td>四川温江大南街形象店</td>\n",
       "      <td>182</td>\n",
       "      <td>0.7143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川龙泉中街形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "      <td>四川龙泉中街形象店</td>\n",
       "      <td>146</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>政策时间：2023年11月22日--12月12日（7天一轮）</td>\n",
       "      <td>(四川新都繁清形象店, 6000)</td>\n",
       "      <td>2023-11-22</td>\n",
       "      <td>2023-12-12</td>\n",
       "      <td>四川新都繁清形象店</td>\n",
       "      <td>186</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀都苹果</td>\n",
       "      <td>7500.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀都苹果, 7500)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>四川成都蜀都形象店</td>\n",
       "      <td>112</td>\n",
       "      <td>0.6667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>蜀泰苹果</td>\n",
       "      <td>6800.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(蜀泰苹果, 6800)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>四川成都蜀泰形象店</td>\n",
       "      <td>116</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>零售四中心四部</td>\n",
       "      <td>桂东苹果</td>\n",
       "      <td>9100.0</td>\n",
       "      <td>一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮</td>\n",
       "      <td>(桂东苹果, 9100)</td>\n",
       "      <td>2023-12-01</td>\n",
       "      <td>2023-12-14</td>\n",
       "      <td>重庆万州形象店</td>\n",
       "      <td>272</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           政策标题       政策门店     政策目标                                 政策时间  \\\n",
       "0    西安门店守卫政策申请       团结苹果  11500.0                     守卫时间：2月19日-2月28日   \n",
       "1    西安门店守卫政策申请     城市立方苹果  17000.0                     守卫时间：2月19日-2月28日   \n",
       "2    西安门店守卫政策申请     宝鸡电子苹果  13000.0                     守卫时间：2月19日-2月28日   \n",
       "3    西安门店守卫政策申请       财富苹果   9800.0                     守卫时间：2月19日-2月28日   \n",
       "4    西安门店守卫政策申请      南大街苹果   8800.0                     守卫时间：2月19日-2月28日   \n",
       "..          ...        ...      ...                                  ...   \n",
       "188     零售四中心四部  四川龙泉中街形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "189     零售四中心四部  四川新都繁清形象店   6000.0       政策时间：2023年11月22日--12月12日（7天一轮）   \n",
       "190     零售四中心四部       蜀都苹果   7500.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "191     零售四中心四部       蜀泰苹果   6800.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "192     零售四中心四部       桂东苹果   9100.0  一、政策时间：2023年12月1日--12月14日（7天一轮）一共两轮   \n",
       "\n",
       "                  政策其它        开始时间        结束时间         门店全称 匹配行号    匹配程度  \n",
       "0        (团结苹果, 11500)  2023-02-19  2023-02-28    陕西咸阳团结形象店   83  0.6667  \n",
       "1      (城市立方苹果, 17000)  2023-02-19  2023-02-28  陕西西安城市立方形象店   58    0.75  \n",
       "2      (宝鸡电子苹果, 13000)  2023-02-19  2023-02-28  陕西宝鸡电子大厦形象店   45    0.75  \n",
       "3         (财富苹果, 9800)  2023-02-19  2023-02-28    四川成都财富形象店   97  0.6667  \n",
       "4        (南大街苹果, 8800)  2023-02-19  2023-02-28   四川温江大南街形象店  182  0.7143  \n",
       "..                 ...         ...         ...          ...  ...     ...  \n",
       "188  (四川龙泉中街形象店, 6000)  2023-11-22  2023-12-12    四川龙泉中街形象店  146     1.0  \n",
       "189  (四川新都繁清形象店, 6000)  2023-11-22  2023-12-12    四川新都繁清形象店  186     1.0  \n",
       "190       (蜀都苹果, 7500)  2023-12-01  2023-12-14    四川成都蜀都形象店  112  0.6667  \n",
       "191       (蜀泰苹果, 6800)  2023-12-01  2023-12-14    四川成都蜀泰形象店  116     1.0  \n",
       "192       (桂东苹果, 9100)  2023-12-01  2023-12-14      重庆万州形象店  272     0.5  \n",
       "\n",
       "[61 rows x 10 columns]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PDF_Seve = PDF_Dst[(PDF_Dst[\"政策目标\"].isna() == False) & (PDF_Dst[\"开始时间\"].isna() == False)]\n",
    "PDF_Seve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "ecc82983",
   "metadata": {},
   "outputs": [],
   "source": [
    "#PDF_Seve.to_excel(\"./Policy_Docx_Extract.xlsx\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b72e094",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
